*Replication file for "Health Certification in Sex Markets: A Field Experiment in Dakar, Senegal"
*Author: Shanthi Manian, Washington State University
*Email address: shanthi.manian@wsu.edu
***************************************************************************

*This replication file requires the following folder structure and files
	*Data/BL_i_replication.dta: Baseline data only, at the individual level
	*Data/Wide_i_replication.dta: Endline data with baseline controls, individual level, in "wide" format 
	*Data/Wide_k_replication.dta: Endline data with baseline controls, transaction level, in "wide" format
	*Data/Panel_i_replication.dta: Baseline and Endline data in panel format, individual level
	*Data/Panel_k_replication.dta: Baseline and Endline data in panel format, transaction level
	*Tables/: Tables are outputted to this folder
	
*Key variables
	* id: Unique participant ID 
	* round: Survey round, referring to either baseline or endline, in panel data
	* transaction: Transaction number in transaction-level. Data were collected for the five most recent sex transactions.
	* T: treatment status (treated = 1)
	* D: certification status (certified = 1) in individual-level data
	* treg: certification status (certified = 1) during a given transaction in transaction-level data 
	* All other variables are labeled in the data.
	
*This code requires the following user-written commands	to produce the tables in the manuscript:
	*iebaltab

clear
version 14

********************** Summary Statistics: Tables 1-3 **********************

//Table 1
use "Data/BL_i_replication.dta", clear

estpost summarize age divorced Sen muslim q18 q22 yrsxwk sxwkmn q55 q25 q38 q27 q28 q50 q53 if ins == 1, d
	
esttab . using "Tables/summ_demo_sxwk.tex", replace booktabs substitute(\begin{tabular} \setlength{\linewidth}{.1cm}\newcommand{\contents}{\begin{tabular}  \end{tabular} \end{tabular}}\setbox0=\hbox{\contents}\setlength{\linewidth}{\wd0-2\tabcolsep-.25em}\contents {l}{\footnotesize {p{\linewidth}}{\footnotesize ) cells("mean(fmt(a2)) sd(fmt(a2)) p50(fmt(a2))  min(fmt(a2)) max(fmt(a2)) count(fmt(0))") label nonumbers noobs nomtitles collabels(Mean S.D. Med. Min. Max. Obs.) addnotes("This table presents summary statistics at baseline for 291 female sex workers comprising the analysis sample (participants who satisfied eligiblity criteria and completed the baseline survey, randomization, and endline survey). Responses of \textit{Don't know} and refusals to respond are coded as missing. FCFA is the currency of Senegal. During the study period, the exchange rate was approximately 588 FCFA = \\$1.")

//Table 2
use "Data/Wide_k_replication.dta", clear

estpost summarize q108_bl q94_bl forcl unprottr anltr, d
	
esttab . using "Tables/summ_trans.tex", replace booktabs substitute(\begin{tabular} \setlength{\linewidth}{.1cm}\newcommand{\contents}{\begin{tabular}  \end{tabular} \end{tabular}}\setbox0=\hbox{\contents}\setlength{\linewidth}{\wd0-2\tabcolsep-.25em}\contents {l}{\footnotesize {p{\linewidth}}{\footnotesize ) cells("mean(fmt(a2)) sd(fmt(a2)) p50(fmt(a2))  min(fmt(a2)) max(fmt(a2)) count(fmt(0))") label nonumbers noobs nomtitles collabels(Mean S.D. Med. Min. Max. Obs.) addnotes("This table presents summary statistics for transaction-level data collected during the baseline survey from 291 female sex workers comprising the analysis sample (participants who satisfied eligiblity criteria and completed the baseline survey, randomization, and endline survey). Each sex worker answered a series of questions about each of her last five sex transactions, generating a sample of 1,455 transactions. Responses of \textit{Don't know} and refusals to respond are coded as missing. FCFA is the currency of Senegal. During the study period, the exchange rate was approximately 588 FCFA = \\$1. Client violence is equal to 1 if sex workers reported any of the following: threat of physical violence, physical violence, sexual violence, forced unprotected sex, threatened to report the sex worker to police.")

//Table 3 
use "Data/BL_i_replication.dta", clear

estpost summarize dr_cur_any dr_cur_cond dr_prev dr if ins == 1, d
	
esttab . using "Tables/summ_STI.tex", replace booktabs substitute(\begin{tabular} \setlength{\linewidth}{.1cm}\newcommand{\contents}{\begin{tabular}  \end{tabular} \end{tabular}}\setbox0=\hbox{\contents}\setlength{\linewidth}{\wd0-2\tabcolsep-.25em}\contents {l}{\footnotesize {p{\linewidth}}{\footnotesize ) cells("mean(fmt(a2)) sd(fmt(a2))  min(fmt(a2)) max(fmt(a2)) count(fmt(0))") label nonumbers noobs nomtitles collabels(Mean S.D. Min. Max. Obs.) addnotes("This table presents summary statistics at baseline for 291 female sex workers comprising the analysis sample (participants who satisfied eligiblity criteria and completed the baseline survey, randomization, and endline survey). Responses of \textit{Don't know} and refusals to respond are coded as missing.")

eststo clear

********************** Results: Tables 4-9 **********************

//Table 4

use "Data/Wide_i_replication.dta", clear

local imbalance "publictr_any_bl"

eststo takeup0: reg D T, r

eststo takeup1: reg D T  i.rand_date, r

eststo takeup2: reg D T `imbalance' i.rand_date, r

esttab takeup* using "Tables/enc_effects.tex", label replace ///
	booktabs substitute(\begin{tabular} \setlength{\linewidth}{.1cm}\newcommand{\contents}{\begin{tabular}  \end{tabular} \end{tabular}}\setbox0=\hbox{\contents}\setlength{\linewidth}{\wd0-2\tabcolsep-.25em}\contents {l}{\footnotesize {p{\linewidth}}{\footnotesize ) ///
	se star(* 0.10 ** 0.05 *** 0.01) keep(T _cons) varlabels(_cons Constant) ///
	mgroups("" "Certification Take-up", pattern(1 1 0) lhs(\textit{Dependent Variable:}) end( \hline)) nomtitles ///
	indicate("Block FE = *.rand_date" "Baseline controls = `imbalance'", labels("X" "")) ///
	nonotes addnotes("@starlegend. Robust standard errors in parentheses. The dependent variable is an indicator for obtaining certification between baseline and follow-up. \textit{Treatment} is an indicator for assignment to the treatment group, which received (i) an informational intervention designed to be persuasive and (ii) an incentive to obtain certification \textit{Block FE} indicates inclusion of fixed effects to account for the public randomization session.  \textit{Baseline controls} indicates inclusion of variables that were imbalanced at baseline due to chance.")
	
	
//Table 5  

eststo clear
use "Data/Panel_k_replication", clear	
  

eststo ITT0: reg q108 T publictr_any_bl if pastmonth==1 & round == 2, vce(cl id)
eststo reg1: xtreg q108 1.treg 2.round 2.round#T if pastmonth == 1, fe vce(cl id)
eststo reg2: xtreg q108 1.treg 2.round 2.round#T i.month if pastmonth == 1, fe vce(cl id)
eststo reg3: xtreg q108 1.treg q93_? 2.round 2.round#T i.month if pastmonth == 1, fe vce(cl id)

esttab ITT0 reg1 reg2 reg3 using "Tables/Price_reg.tex", replace label se star(* 0.10 ** 0.05 *** 0.01) ///
	booktabs ///
	substitute(\begin{tabular} \setlength{\linewidth}{.1cm}\newcommand{\contents}{\begin{tabular}  \end{tabular} \end{tabular}}\setbox0=\hbox{\contents}\setlength{\linewidth}{\wd0-2\tabcolsep-.25em}\contents {l}{\footnotesize {p{\linewidth}}{\footnotesize ) ///
	varlabels(T "Treatment" _cons Constant) noomitted ///
	indicate("Round FE = 2.round" "Treatment controls =2.round#1.T" "Month fixed effects = ?.month ??.month" "Sex act controls = q93_?", labels("X" "") ) ///
	drop(publictr_any_bl) ///
	mlabels("ITT" "FE" "FE" "FE") ///
	mgroups("Transaction Price (FCFA)", pattern(1 0 0 0) span prefix(\multicolumn{@span}{c}{) suffix(}) lhs(\textit{Dependent Variable:})  end( \hline)) ///
	nonotes addnotes("@starlegend. Standard errors in parentheses, clustered at individual level. Analysis is conducted at the transaction level. The sample is restricted to transactions in the month prior to survey to maintain a comparable sample with Table \ref{tab:price-sti}. \textit{Treatment} is an indicator for assignment to the treatment group, which received (i) an informational intervention designed to be persuasive and (ii) an incentive to obtain certification. \textit{Certified} is an indicator for the sex worker having a valid certification when the transaction was completed. Sex act controls include types of sexual activities completed during the transaction, condom use, and a series of client characteristics reported by the sex worker. The column heading FE indicates individual fixed effects.")
	
//Table 6

eststo STIany: xtreg q108 STI_any 2.round 2.round#T i.month if pastmonth == 1, fe vce(cl id)
eststo STIvis: xtreg q108 1.STI_vis 2.round 2.round#T if pastmonth == 1, fe vce(cl id)
eststo STIvis_c: xtreg q108 1.STI_vis 2.round 2.round#T i.month q93_? if pastmonth == 1, fe vce(cl id)
eststo STIvisinv_c: xtreg q108 1.STI_vis STI_invis 2.round 2.round#T i.month q93_? if pastmonth == 1, fe vce(cl id)
eststo regSTI: xtreg q108 1.treg 1.STI_vis 2.round 2.round#T i.month q93_?  if pastmonth == 1, fe vce(cl id)

esttab STIany STIvis STIvis_c STIvisinv_c regSTI using "Tables/Price_STI_pan.tex", replace label se star(* 0.10 ** 0.05 *** 0.01) ///
	booktabs ///
	substitute(\begin{tabular} \setlength{\linewidth}{.1cm}\newcommand{\contents}{\begin{tabular}  \end{tabular} \end{tabular}}\setbox0=\hbox{\contents}\setlength{\linewidth}{\wd0-2\tabcolsep-.25em}\contents {l}{\footnotesize {p{\linewidth}}{\footnotesize ) ///
	varlabels(_cons Constant) noomitted ///
	indicate("Month fixed effects = ?.month ??.month" "Sex act controls = q93_?", labels("X" "")) ///
	drop(2.round 2.round#1.T) ///
	nomtitles ///
	mgroups("Transaction Price", pattern(1 0 0 0 0 0) span prefix(\multicolumn{@span}{c}{) suffix(}) lhs(\textit{Dependent Variable:})  end( \hline)) ///
	nonotes addnotes("@starlegend. Standard errors in parentheses, clustered at individual level. Analysis is conducted at the transaction level using data collected at baseline and endline. The sample is restricted to transactions in the month prior to the survey. At baseline and endline, sex workers reported up to three recent STI episodes. \textit{Any STI} is an indicator for reporting an episode of STI symptoms in the past month. STI episodes are classified as either visible or invisible. \textit{Visible STI} is an indicator for an episode with visible symptoms, and \textit{Invisible STI} is an indicator for an episode with no visible symtpoms. \textit{Actively certified} is an indicator for the sex worker having a valid certification when the transaction was completed. Individual and round fixed effects and controls for treatment group are included in all regressions.")

	
//Table 7

eststo clear
use "Data/Wide_i_replication.dta", clear

local reasonlist "q65g_I_el q65g_H_el q65g_N_el q65g_K_el q65g_M_el q65g_J_el q65g_A_el q65g_E_el q65g_C_el q65g_G_el q65g_D_el q65g_B_el"

eststo never0: estpost summarize `reasonlist' if never == 0
eststo never1: estpost summarize `reasonlist' if never == 1
eststo neverdiff: estpost prtest `reasonlist', by(never)
		
esttab never0 never1 neverdiff using "Tables/q65i_prtest_el.tex", cells("mean(fmt(a2) pattern(1 1 0)) b(fmt(a2) pattern(0 0 1)) p(star fmt(2) pattern(0 0 1))" sum(par fmt(0) pattern(1 1 0))) label replace noobs mtitles("WTA\(<\infty\)" "WTA\(=\infty\)" "Difference") collabels("mean(n)" "(1)-(2)" "p-val.") star(* 0.10 ** 0.05 *** 0.01) 
				
//Table 8       
eststo clear
use "Data/Wide_i_replication.dta", clear

eststo confind: reg never confid D T, r
eststo extind: reg  never extstigma D T, r
eststo selfind: reg never selfstigma D T, r
eststo allind: reg never confid extstigma selfstigma D T, r

esttab confind extind selfind allind using "Tables/never_stigma_ind.tex", label booktabs ///
substitute(\begin{tabular} \setlength{\linewidth}{.1cm}\newcommand{\contents}{\begin{tabular}  \end{tabular} \end{tabular}}\setbox0=\hbox{\contents}\setlength{\linewidth}{\wd0-2\tabcolsep-.25em}\contents {l}{\footnotesize {p{\linewidth}}{\footnotesize ) /// 
compress replace se star(* 0.10 ** 0.05 *** 0.01) varlabels(_cons Constant) drop(D T) noomitted nonotes addnotes("@starlegend. Robust standard errors in parentheses. Controls for treatment and certification status included in all regressions. Regressions are estimated on the subsample who were asked the willingness-to-accept question. ``Inf. WTA'' refers to the statement that there is no incentive amount that would convince the participant to certify (i.e. willingness to accept is infinite). \textit{Confidentiality index} includes: whether subject believes information provided during registration is confidential; who can access registration list. \textit{Community stigma index} includes: \textit{Afraid someone will see me at the clinic} and \textit{Afraid someone will find the health card}; whether subject has ever been to registration clinic; and whether subject solicits or completes transactions in public. \textit{Internalized stigma index} includes \textit{Do not want to assume sex worker identity} and agreement with \textit{Some women exchange sex for money but are not sex workers.} ") 

//Table 9
eststo clear
use "Data/Wide_i_replication.dta", clear

eststo confind_WTA: reg WTA_full confid D T if WTA<100, r
eststo extind_WTA: reg  WTA_full extstigma D T if WTA<100, r
eststo selfind_WTA: reg WTA_full selfstigma D T if WTA<100, r
eststo allind_WTA: reg WTA_full confid extstigma selfstigma D T if WTA<100, r

esttab confind_WTA extind_WTA selfind_WTA allind_WTA using "Tables/WTA_stigma_ind.tex", label booktabs ///
substitute(\begin{tabular} \setlength{\linewidth}{.1cm}\newcommand{\contents}{\begin{tabular}  \end{tabular} \end{tabular}}\setbox0=\hbox{\contents}\setlength{\linewidth}{\wd0-2\tabcolsep-.25em}\contents {l}{\footnotesize {p{\linewidth}}{\footnotesize ) /// 
compress replace se star(* 0.10 ** 0.05 *** 0.01) varlabels(_cons Constant) drop(D T) noomitted nonotes addnotes("@starlegend. Robust standard errors in parentheses. Controls for treatment and certification status included in all regressions. Regressions are estimated on the subsample who were asked the willingness-to-accept question. ``WTA'' is the response to the question, ``What is the minimum incentive you would accept to get certified?'' in USD. Responses that there is no incentive amount that would convince the participant to certify are excluded. \textit{Confidentiality index} includes: whether subject believes information provided during registration is confidential; who can access registration list. \textit{Community stigma index} includes: \textit{Afraid someone will see me at the clinic} and \textit{Afraid someone will find the health card}; whether subject has ever been to registration clinic; and whether subject solicits or completes transactions in public. \textit{Internalized stigma index} includes \textit{Do not want to assume sex worker identity} and agreement with \textit{Some women exchange sex for money but are not sex workers.} ") 

********************** Appendix **********************

***** Attrition: Table A1 *****
eststo clear
use "Data/BL_i_replication.dta", clear

eststo attrit1: reg attrit 1.T, r
eststo attrit2: reg attrit 1.T##c.age 1.T##1.divorced 1.T##c.q18 1.T##c.q22 1.T##c.yrsxwk 1.T##1.sxwkmn 1.T##1.q55 1.T##c.q25 1.T##c.q38 1.T##c.q27 1.T##c.q28 1.T##1.q50, r
		
test 1.T 1.T#c.age 1.T#1.divorced 1.T#c.q18 1.T#c.q22 1.T#c.yrsxwk 1.T#1.sxwkmn 1.T#1.q55 1.T#c.q25 1.T#c.q38 1.T#c.q27 1.T#c.q28 1.T#1.q50
estadd scalar ftestp=r(p)
		
esttab attrit1 attrit2 using "Tables/attrition.tex", tex se label replace star(* 0.10 ** 0.05 *** 0.01) drop(age 1.divorced q18 q22 yrsxwk 1.sxwkmn 1.q55 q25 q38 q27 q28 1.q50) scalars("ftestp F test of joint significance (p-val)")	
	
***** Balance: Tables A2-A5 *****

eststo clear
use "Data/BL_i_replication.dta", clear


local balancevars1 "q28 regknow age arrests_n jail public_n publictr_n STI_n STI_sev q38 unprotn"

preserve
iebaltab `balancevars1', grpvar(T) grplabels(0 Control @ 1 Treatment) vce(robust) fix(rand_date) savetex(Tables/baltab1.tex) replace rowv stats(pair(p)) tblnon nonote addnote(Standard errors are robust. Block fixed effects included in all estimation regressions. ***, **, and * indicate significance at the 1, 5, and 10 percent critical level.)
restore

local balancevars2 "q67 unprottr_n HIVknow dr_cur q75 q84 lastHIV regprem cl_ifreg_n cl_seecrd_n"

preserve
iebaltab `balancevars2', grpvar(T) grplabels(0 Control @ 1 Treatment) vce(robust) fix(rand_date) savetex(Tables/baltab2.tex) replace rowv stats(pair(p)) tblnon nonote addnote(Standard errors are robust. Block fixed effects included in all estimation regressions. ***, **, and * indicate significance at the 1, 5, and 10 percent critical level.)
restore

preserve
iebaltab `balancevars1' if ins == 1, grpvar(T) grplabels(0 Control @ 1 Treatment) vce(robust) fix(rand_date) savetex(Tables/baltab3.tex) replace rowv stats(pair(p)) tblnon nonote addnote(Standard errors are robust. Block fixed effects included in all estimation regressions. ***, **, and * indicate significance at the 1, 5, and 10 percent critical level.)
restore

local balancevars2 "q67 unprottr_n HIVknow dr_cur q75 q84 lastHIV regprem cl_ifreg_n cl_seecrd_n"

preserve
iebaltab `balancevars2' if ins == 1, grpvar(T) grplabels(0 Control @ 1 Treatment) vce(robust) fix(rand_date) savetex(Tables/baltab4.tex) replace rowv stats(pair(p)) tblnon nonote addnote(Standard errors are robust. Block fixed effects included in all estimation regressions. ***, **, and * indicate significance at the 1, 5, and 10 percent critical level.)
restore


***** Robustness: Tables A6-A8 *****
eststo clear
use "Data/Panel_k_replication", clear	

//Table A6
eststo wins99: xtreg q108_w99 1.treg 2.round 2.round#T if pastmonth == 1, fe vce(cl id)
eststo wins95: xtreg q108_w95 1.treg 2.round 2.round#T if pastmonth == 1, fe vce(cl id)
eststo ihs: xtreg price_ihs 1.treg 2.round 2.round#T if pastmonth == 1, fe vce(cl id)

esttab wins99 wins95 ihs using "Tables/Price_reg_robust.tex", replace label se star(* 0.10 ** 0.05 *** 0.01) ///
booktabs ///
substitute(\begin{tabular} \setlength{\linewidth}{.1cm}\newcommand{\contents}{\begin{tabular}  \end{tabular} \end{tabular}}\setbox0=\hbox{\contents}\setlength{\linewidth}{\wd0-2\tabcolsep-.25em}\contents {l}{\footnotesize {p{\linewidth}}{\footnotesize ) ///
varlabels(T "Treatment" _cons Constant) noomitted ///
indicate("Round FE = 2.round" "Treatment controls =2.round#1.T", labels("X" "") ) ///
mlabels("99\% Winsor Price" "95\% Winsor Price" "IHS Price") ///
mgroups("Transaction Price (FCFA)", pattern(1 0 0 0) span prefix(\multicolumn{@span}{c}{) suffix(}) lhs(\textit{Dependent Variable:})  end( \hline)) ///
nonotes addnotes("@starlegend. Standard errors in parentheses, clustered at individual level. Analysis is conducted at the transaction level. \textit{Treatment} is an indicator for assignment to the treatment group, which received (i) an informational intervention designed to be persuasive and (ii) an incentive to obtain certification. \textit{Certified} is an indicator for the sex worker having a valid certification when the transaction was completed. \textit{99% Winsor Price} and \textit{99% Winsor Price} are the transaction price winsorized at the 99th and 95th percentiles respectively. \textit{IHS Price} is the inverse hyperbolic sine transformation of the transaction price. All regressions include individual fixed effects.") 

//Table A7
eststo clear
use "Data/Wide_i_replication.dta", clear

local imbalance "publictr_any_bl"
eststo quant_itt: reg q44_el T `imbalance' i.rand_date, r

use "Data/Panel_i_replication", clear	

eststo quant2: xtreg q44 curr_reg 2.round 2.round#T i.month unprotn, fe vce(cl id)
eststo clients: xtreg q38 curr_reg 2.round 2.round#T i.month unprotn, fe vce(cl id)
eststo loginc: xtreg loginc curr_reg 2.round 2.round#T i.month unprotn, fe vce(cl id)

esttab quant_itt quant2 clients loginc using "Tables/Extmarg_reg.tex", label tex compress replace se star(* 0.10 ** 0.05 *** 0.01) varlabels(_cons Constant T Treatment) noomitted nonotes indicate("Block FE = *.rand_date""Month fixed effects = ?.month ??.month" "Unprotected sex control = unprotn") drop(publictr_any_bl 2.round 2.round#1.T) addnotes("Standard errors in parentheses, clustered at individual level" "@starlegend" "Individual and round fixed effects, treatment controls included in all regressions.")

//Table A8
    eststo STIext1: xtreg q44 STI_any 2.round 2.round#T, fe vce(cl id)
    eststo STIext2: xtreg q44 STI_vis 2.round 2.round#T, fe vce(cl id)
    eststo STIext3: xtreg q44 STI_vis STI_invis 2.round 2.round#T, fe vce(cl id)


     esttab STIext1 STIext2 STIext3 using "Tables/Extmarg_STI.tex", label tex compress replace se star(* 0.10 ** 0.05 *** 0.01) varlabels(_cons Constant) noomitted nonotes drop(2.round 2.round#1.T) addnotes("Standard errors in parentheses, clustered at individual level" "@starlegend" "Individual and round fixed effects, treatment controls included in all regressions.")















